<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>付款成功页面</title>
<link rel="stylesheet" type="text/css" href="../static/css/amazeui.css" />
<link href="../static/css/admin.css" rel="stylesheet" type="text/css">
<link href="../static/css/demo.css" rel="stylesheet" type="text/css" />
<link href="../static/css/sustyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../static/js/myinit.js"></script>
<script type="text/javascript" src="../static/js/qrcode.js"></script>
</head>

<body>

	<!--顶部导航条 -->
	<div class="am-container header">
		<ul class="message-l">
			<div class="topMessage">
				<div class="menu-hd">
					<a href="#" target="_top" class="h">亲，请登录</a> <a href="#"
						target="_top">免费注册</a>
				</div>
			</div>
		</ul>
		<ul class="message-r">
			<div class="topMessage home">
				<div class="menu-hd">
					<a href="#" target="_top" class="h">商城首页</a>
				</div>
			</div>
			<div class="topMessage my-shangcheng">
				<div class="menu-hd MyShangcheng">
					<a href="#" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a>
				</div>
			</div>
			<div class="topMessage mini-cart">
				<div class="menu-hd">
					<a id="mc-menu-hd" href="#" target="_top"><i
						class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong
						id="J_MiniCartNum" class="h">0</strong></a>
				</div>
			</div>
			<div class="topMessage favorite">
				<div class="menu-hd">
					<a href="#" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a>
				</div>
			</div>
		</ul>
	</div>

	<!--悬浮搜索框-->

	<div class="nav white">
		<div class="logo">
			<img src="../static/img/logo.png" />
		</div>
		<div class="logoBig">
			<li><img src="../static/img/logobig.png" /></li>
		</div>
		<div class="search-bar pr">
			<a name="index_none_header_sysc" href="#"></a>
			<form>
				<input id="searchInput" name="index_none_header_sysc" type="text"
					placeholder="搜索" autocomplete="off"> <input
					id="ai-topsearch" class="submit" value="搜索" index="1" type="submit">
			</form>
		</div>
	</div>
	<div class="clear"></div>
	<div class="take-delivery" style="min-height: 400px">
		<div class="status" style="display: none;"  id="success_div">
			<h2 id="status">您已成功付款</h2>
			 
		</div>
		
		
		<div style="display: none;" id="pay_div">
		
			<input placeholder="输入会员余额支付密码" id="yue_input" type="password"/><button id="cmf_zhifu_yue">确认支付</button>
			<div>选择微信支付,请扫下方二维码</div>
			
			<div id="weixinzhifu_erweima"></div>
		
		</div>



	</div>
	<div class="footer ">
		<div class="footer-hd">
			<p>
				<img src="../static/img/duo.png" style="width: 25px" />品类齐全<b>|</b><img
					src="../static/img/kuai.png" style="width: 25px" />多仓直发<b>|</b><img
					src="../static/img/hao.png" style="width: 25px" />正品行货<b>|</b><img
					src="../static/img/sheng.png" style="width: 25px" />天天低价
			</p>
		</div>
		<div class="footer-bd "></div>
	</div>
	
	<script type="text/javascript">
		ajaxSettingsasync(false);
		
		var orderid = getUrldata('ORDERID');
		var openid='';
		getOpenid();
		
		function getOpenid(){
			var urll = '/weixin/getopenid/';
			var aa={};
			aa.code='';
			$.ajax({
				url : urll,
				data :  JSON.stringify(aa),
				async:isasync,
				contentType : "application/json;",
				dataType : "json",
				type : "POST",
				success :function(aa){
					openid = aa.openid;
					$('#yue_input').val('');
				
				},
				error: function(){
				 	toastwithaction('尚未登录',function(){
						document.location.href="login_pc.html";
					});
						
				}
			});
		}
		var time;
		$(document).ready(function(){
			initorder();
			time=setInterval('initorder()',10000);
			
		});
		
		function initorder(){
			var url = '/webserver/api/v1/orderitem/?format=json&order='+orderid;
			$.getJSON(url,function(rs){
				var object = rs.objects[0];
				var order = object.order;
				if(order.status=='已下单'){
					$('#pay_div').show();
					initerweima(order.id);
				}else if(order.status=='已支付'){
					clearInterval(time);
					$('#pay_div').hide();
					$('#success_div').show();
				}else{
					$('#status').html(order.status);
					$('#success_div').show();
				}
			
			},'json');
		}
		
		function initerweima(oid){
			var url_erweima="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1ef1259eec8b148d&redirect_uri=http%3a%2f%2fwww.tiantianhw.cn%2fmshop%2ferweimaweixinpay.html%3fORDERID%3d"+oid+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
			$('#weixinzhifu_erweima').empty();
			var qrcode = new QRCode('weixinzhifu_erweima', {
				text: url_erweima,
				width: 300,
				height: 300,
				colorDark : '#000000',
				colorLight : '#ffffff',
				correctLevel : QRCode.CorrectLevel.L
			});
			
		}
		
		function getyue(order){
		 
			var url="/webserver/api/v1/user/?format=json&openid="+openid;
			$.getJSON(url,function(rs){
				var object=rs.objects[0];
				var balance=object.balance;
				balance=parseFloat(balance).toFixed(2);
				
				//$('#yue').html(balance);
				var pas=$('#yue_input').val();
				if(object.password==pas){
					
				}else{
					alert('密码错误');
					return;
				}
				 
				
				 
				 
				payincash(order.id);
				
			});
		}
		
		$('#cmf_zhifu_yue').click(function(){
			var url = '/webserver/api/v1/orderitem/?format=json&order='+orderid;
			$.getJSON(url,function(rs){
				var object = rs.objects[0];
				var order = object.order;
				if(order.status=='已下单'){
					
					
					getyue(order);
					
					 
				}else{
					alert('订单状态正确');
				}
			
			},'json');
			
		});
		
		function payincash(oid){
			var url="/weixin/payorder/";
			$.post(url,{"orderid":oid},function(aa){
				if(aa.code=='true'){
					setTimeout(function(){
						 
					
						toastwithaction("支付成功",function(){
							document.location.href=document.location.href;
							
						});
						
					
					},500);
					
						
				}else{
					alert('余额不足!');
				}
			}, "json");
		}
		
		
	
	</script>
</body>
</html>
